package com.cl.websocketboot.entity;

import com.cl.websocketboot.constant.Constant;
import com.cl.websocketboot.utils.JsonUtil;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.UUID;

@Data
public class Message {
    private String msgId;
    private String roomId;
    private String username;
    private String content;
    //    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
//    @JsonSerialize(using = LocalDateTimeSerializer.class)
//    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime sendDateTime;

    public static Message systemMessage(String roomId, String text) {
        Message message = new Message();
        message.setMsgId(UUID.randomUUID().toString());
        message.setContent(text);
        message.setRoomId(roomId);
        message.setUsername(Constant.SYSTEM_STR);
        message.setSendDateTime(LocalDateTime.now());
        return message;
    }

    public static String systemMessageJson(String roomId, String text) {
        Message message = systemMessage(roomId, text);
        Constant.saveMsg(roomId, message);
        return JsonUtil.toString(message);
    }
}
